/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.welchapps.nporganizer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View;
import android.net.TrafficStats;
import android.os.Process;



public class DebugAcc extends Activity {

    /**
     * Standard projection for the interesting columns of a normal note.
     */

    private TextView mText;


    /**
     * A custom EditText that draws lines between each line of text that is displayed.
     */


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the layout for this activity.  You can find it in res/layout/note_editor.xml
        setContentView(R.layout.debug_acc);

        mText = (TextView) this.findViewById(R.id.textView3); 
        

        

    }

    @Override
    protected void onResume() {
    	long bytesrx =  TrafficStats.getUidRxBytes(Process.myUid());
    	long bytestx =  TrafficStats.getUidTxBytes(Process.myUid());
        super.onResume();
        SharedPreferences settings1 = getSharedPreferences("filterPref",0);
        SharedPreferences settings2 = getSharedPreferences("defSettings",0);
        
        String filter_val = settings1.getString("value","");
        String filter_cat = settings1.getString("category","");
        String filter_stat = settings1.getString("status","");
        
        String ver = settings2.getString("version","");
        String sort = settings2.getString("sort_order","");
        String upload = settings2.getString("upload_time","");
        boolean new_upload = settings2.getBoolean("new_upload",false);
        Integer runs = settings2.getInt("runs",0);
        
        String[] fileNames = getExternalFilesDir(null).list();
        Integer totalIMG = 0;
        for (int i = 0; i< fileNames.length; i++)
        {
          if (fileNames[i].contains(".jpg"))
            {
              totalIMG++;
             }
          }
        
        
        mText.setText("Version: " + ver + 
        		"\nRuns: " + runs.toString() +
        		"\nImage Count: " + totalIMG.toString() +
        		"\nFilter Value: " + filter_val +
        		"\nFilter Cat: " + filter_cat + 
        		"\nFilter Stat: " + filter_stat +
        		"\nSort order: " + sort +
        		"\nUpload Time: " + upload + 
        		"\nNew upload: " + new_upload +
        		"\nBytes rx: " + bytesrx + 
        		"\nBytes tx: " + bytestx);
        		


    }



    @Override
    protected void onPause() {
        super.onPause();

    }

    public void okFilter(View view){

    	finish();
    }
    
    public void export(View view){
        try {
            File sd = getExternalFilesDir(null);

            if (sd.canWrite()) {
                String backupDBPath = "notepad.db";
                //File currentDB = new File(data, currentDBPath);
                File currentDB = getDatabasePath("notepad.db");
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {
        }
    }

}
